package com.neiru.pruebas.ar.figure;

import com.neiru.pruebas.ar.opengl.utils.Colors;

public class Cube extends Mesh {
	
	public float width;
	public float height;
	public float depth;
	public boolean destroyed = false;
	
	public Cube(float width, float height, float depth, String color) {
        width  /= 2;
        height /= 2;
        depth  /= 2;
 
        this.width = width;
        this.height = height;
        this.depth = depth;
        
        float vertices[] = { -width, -height, -depth, // 0
                              width, -height, -depth, // 1
                              width,  height, -depth, // 2
                             -width,  height, -depth, // 3
                             -width, -height,  depth, // 4
                              width, -height,  depth, // 5
                              width,  height,  depth, // 6
                             -width,  height,  depth, // 7
        };
 
        short indices[] = { 0, 4, 5,
                            0, 5, 1,
                            1, 5, 6,
                            1, 6, 2,
                            2, 6, 7,
                            2, 7, 3,
                            3, 7, 4,
                            3, 4, 0,
                            4, 7, 6,
                            4, 6, 5,
                            3, 0, 1,
                            3, 1, 2, };
        
        float[] color1;
        if("red".equals(color)) {
        	color1 = Colors.RED;
    	} else if("green".equals(color)) {
    		color1 = Colors.GREEN;
    	} else {
    		color1 = Colors.BLUE;
    	}
        setIndices(indices);
        setVertices(vertices);
        setColor(color1[0],color1[1],color1[2],color1[3]);
    }
	
	public boolean isColision(Cube cube){
		float thisMinX = this.x - (this.width / 2);
		float thisMaxX = this.x + (this.width / 2);
		float paramMinX = cube.x - (cube.width / 2);
		float paramMaxX = cube.x + (cube.width / 2);

		float thisMinY = this.y - (this.width / 2);
		float thisMaxY = this.y + (this.width / 2);
		float paramMinY = cube.y - (cube.width / 2);
		float paramMaxY = cube.y + (cube.width / 2);
		
		float thisMinZ = this.z - (this.width / 2);
		float thisMaxZ = this.z + (this.width / 2);
		float paramMinZ = cube.z - (cube.width / 2);
		float paramMaxZ = cube.z + (cube.width / 2);
		
		if(cube == this) {
			return false;
		}
		
		if((thisMaxX < paramMinX) && (thisMinX < paramMinX)) {
			return false;
		}
		if((thisMaxX > paramMaxX) && (thisMinX > paramMaxX)) {
			return false;
		}
		
		
		if((thisMaxY < paramMinY) && (thisMinY < paramMinY)) {
			return false;
		}
		if((thisMaxY > paramMaxY) && (thisMinY > paramMaxY)) {
			return false;
		}
		
		
		if((thisMaxZ < paramMinZ) && (thisMinZ < paramMinZ)) {
			return false;
		}
		if((thisMaxZ > paramMaxZ) && (thisMinZ > paramMaxZ)) {
			return false;
		}
		
		return true;
	}
}
